package Ep01_Array.Mar01st_0027;

/**
 * @author Jimmy Zhan WORKSTATION
 * @date 2023/3/2 14:11
 * 说明：0027 原地移除数组元素
 */

public class Mine {

    public static void main(String[] args) {
        int[] nums = {0,1,2,2,3,0,4,2};
        Mine m = new Mine();
        System.out.println(m.removeElement(nums, 2));
    }
    public int removeElement(int[] nums, int val){
        int pointer = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != val){
                nums[pointer] = nums[i];
                pointer++;
            }
        }
        return pointer;
    }
}
